package com.uzai.console.web.mini;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.mini.minicode.MiniCodeDto;
import com.uzai.console.dto.mini.minicode.MiniCodeIdDto;
import com.uzai.console.dto.mini.minicode.MiniCodeQuery;
import com.uzai.console.dto.mini.minicode.MiniCodeRefreshDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.mini.MiniCodeService;
import com.uzai.console.vo.mini.miniaddress.MiniAreaVo;
import com.uzai.console.vo.mini.minicode.MiniCodeVo;
import com.uzai.console.vo.mini.minicode.MiniTemplateVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小程序代码管理管理
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "代码管理",tags = "微信小程序|代码管理")
@ApiSort(7)
@RestController
public class MiniCodeController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(MiniCodeController.class);

    @Autowired
    private MiniCodeService miniCodeService;

    @ApiOperation(value = "分页查询小程序代码管理列表", notes = "分页查询小程序代码管理列表", response = MiniCodeVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/miniCode/findByPage")
    public Object fingMiniCodeByPage(@RequestBody MiniCodeQuery miniCodeQuery){
        return miniCodeService.findMiniCodeByPage(miniCodeQuery);
    }

    @ApiOperation(value = "查询小程序代码管理详情", notes = "查询小程序代码管理详情", response = MiniCodeVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/miniCode/findById")
    public Object fingMiniCodeById(@RequestBody MiniCodeIdDto miniCodeIdDto){
        return miniCodeService.findMiniCodeById(miniCodeIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加小程序代码管理", notes = "添加小程序代码管理")
    @ApiOperationSupport(order = 3)
    @PostMapping("/miniCode/add")
    public Object addMiniCode(@RequestBody MiniCodeDto miniCodeDto){
        miniCodeService.addMiniCode(miniCodeDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改小程序代码管理信息", notes = "修改小程序代码管理信息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/miniCode/update")
    public Object updateMiniCode(@RequestBody MiniCodeDto miniCodeDto){
        miniCodeService.updateMiniCode(miniCodeDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除小程序代码管理信息", notes = "删除小程序代码管理信息")
    @ApiOperationSupport(order = 4)
    @PostMapping("/miniCode/delete")
    public Object deleteMiniCode(@RequestBody MiniCodeIdDto miniCodeIdDto){
        miniCodeService.deleteMiniCode(miniCodeIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "查询小程序代码模板列表", notes = "查询小程序代码模板列表", response = MiniTemplateVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/miniCode/template/findByList")
    public Object fingMiniTemplateList(){
        return miniCodeService.fingMiniTemplateList();
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序刷代码管理刷新最新版本", notes = "小程序刷代码管理刷新最新版本", response = Boolean.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/miniCode/refresh")
    public Object refreshMiniCode(@RequestBody MiniCodeRefreshDto miniCodeRefreshDto){
        miniCodeService.refreshMiniCode(miniCodeRefreshDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序刷代码管理审提交审核", notes = "小程序刷代码管理审提交审核",response = Boolean.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/miniCode/check")
    public Object checkMiniCode(@RequestBody MiniCodeIdDto miniCodeIdDto){
        miniCodeService.checkMiniCode(miniCodeIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniCode, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序刷代码管理发布版本", notes = "小程序刷代码管理发布版本",response = Boolean.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/miniCode/release")
    public Object releaseMiniCode(@RequestBody MiniCodeIdDto miniCodeIdDto){
        miniCodeService.releaseMiniCode(miniCodeIdDto);
        return true;
    }

    @ApiOperation(value = "查询小程序代码管理最新版本信息", notes = "查询小程序代码管理最新版本信息", response = MiniCodeVo.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/miniCode/findNewest")
    public Object findNewestByAppId(@RequestBody MiniCodeRefreshDto miniCodeRefreshDto){
        return miniCodeService.findNewestByAppId(miniCodeRefreshDto);
    }
}
